package com.lemon.tuvi2015;

import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.TypedValue;
import android.view.View;
import android.view.View.OnClickListener;

import com.lemon.tuvi2015.util.BaseEngine;
import com.lemon.tuvi2015.util.TagName;
import com.lemon.tuvi2015.view.CustomActionbar;
import com.lemon.tuvi2015.view.PagerSlidingTabStrip;

public class BoiActivity extends FragmentActivity {

	private PagerSlidingTabStrip tabs;
	ViewPager viewPager;
	AlbumListAdapter adapter;
	String ID;
	CustomActionbar actionbar;
	View main;
	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.boinotruoi_layout);
		initview();
		Bundle extras = getIntent().getExtras();
		if (getIntent().hasExtra(TagName.KEY))
			ID = (String) extras.getString(TagName.KEY);
		
		initActionbar();
	}

	void initview() {
		main=findViewById(R.id.main);
		tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
		viewPager = (ViewPager) findViewById(R.id.viewPager);
		adapter = new AlbumListAdapter(getSupportFragmentManager());
		final int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
		viewPager.setPageMargin(pageMargin);
		viewPager.setAdapter(adapter);
		viewPager.setCurrentItem(0);
		tabs.setViewPager(viewPager);
	}
	void initActionbar() {
		actionbar = (CustomActionbar) findViewById(R.id.header);
		OnClickListener listenerBack = new OnClickListener() {

			@Override
			public void onClick(View v) {
				onBackPressed();
			}
		};
		OnClickListener listenerShare = new OnClickListener() {

			@SuppressWarnings("deprecation")
			@Override
			public void onClick(View v) {
				BaseEngine.shareBitmap(BoiActivity.this,  BaseEngine.ConvertViewtoBitmap(BoiActivity.this, main));
			}
		};
		actionbar.setActionbar(R.string.home_menu_boinotruoi, listenerBack, listenerShare);
	}
	public class AlbumListAdapter extends FragmentStatePagerAdapter {
		public AlbumListAdapter(FragmentManager fm) {
			super(fm);
		}

		String[] listType = { getResources().getString(R.string.boinotruoi_khuonmat), getResources().getString(R.string.boinotruoi_cothe) };

		@Override
		public CharSequence getPageTitle(int position) {
			return listType[position];
		}

		@Override
		public int getCount() {
			return listType.length;
		}

		@Override
		public Parcelable saveState() {
			return null;
		}

		@Override
		public Fragment getItem(int i) {
			switch (i) {
			case 1:
				return new BoiCotheFragment();
			default:
				return new BoiKhuonmatFragment();
			}
		}
	}
}
